// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-7-11 23:07:16
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   DevModeActionServlet.java

package com.creawor.struts;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.struts.action.ActionServlet;

public class DevModeActionServlet extends ActionServlet
{

    public DevModeActionServlet()
    {
    }

    protected void process(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        if(devMode)
        {
            log.info("start reload struts config");
            destroy();
            init(getServletConfig());
            removeAllRequestProcessor();
        }
        super.process(request, response);
    }

    public void removeAllRequestProcessor()
    {
        for(Enumeration e = getServletContext().getAttributeNames(); e.hasMoreElements();)
        {
            String name = (String)e.nextElement();
            if(name.startsWith("org.apache.struts.action.REQUEST_PROCESSOR"))
                getServletContext().setAttribute(name, null);
        }

    }

    private static String DEFAULT_STRUTS_CONFIG_NAME;
    private static Properties properties;
    private static boolean devMode;
    static Class class$0;

    static 
    {
        DEFAULT_STRUTS_CONFIG_NAME = "struts1.properties";
        properties = new Properties();
        try
        {
            InputStream strutsConfigIn = com.creawor.struts.DevModeActionServlet.class.getClassLoader().getResourceAsStream(DEFAULT_STRUTS_CONFIG_NAME);
            if(strutsConfigIn != null)
            {
                log.info((new StringBuilder("load ")).append(DEFAULT_STRUTS_CONFIG_NAME).append(" file in classpath").toString());
                properties.load(strutsConfigIn);
                strutsConfigIn.close();
            } else
            {
                log.info((new StringBuilder("not found ")).append(DEFAULT_STRUTS_CONFIG_NAME).append(" file in classpath").toString());
            }
        }
        catch(Exception e)
        {
            log.warn((new StringBuilder("count not load ")).append(DEFAULT_STRUTS_CONFIG_NAME).append(",cause=").append(e.toString()).toString(), e);
        }
        devMode = Boolean.valueOf(properties.getProperty("devMode", "false")).booleanValue();
        log.info((new StringBuilder("struts devMode=")).append(devMode).toString());
    }
}